//
//  CustomPaopaoView.m
//  MemberProject
//
//  Created by vincent luo on 15/5/2.
//  Copyright (c) 2015年 MAC OS X. All rights reserved.
//

#import "CustomPaopaoView.h"

@implementation CustomPaopaoView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.

*/
- (void)drawRect:(CGRect)rect {
    // Drawing code
    CGRect bubbleRect = rect;
    CGFloat _topMargin = 2.0;
    CGFloat _pointerSize = 12.0;
    CGFloat _sidePadding = 2.0;
    CGFloat _borderWidth = 1.0;
    
    CGSize					_bubbleSize;
    CGFloat					_cornerRadius = 5;
    BOOL					_highlight;
    CGPoint					_targetPoint = CGPointMake(10, 10);
    CGFloat					_bubblePaddingX;
    CGFloat					_bubblePaddingY;
    
    CGContextRef c = UIGraphicsGetCurrentContext();
    
    CGContextSetRGBStrokeColor(c, 0.0, 0.0, 0.0, 0.5);
    // black
    CGContextSetLineWidth(c, _borderWidth);
    CGContextSetRGBFillColor(c, 0.5, 0.5, 0.5, 1);
    
    CGMutablePathRef bubblePath = CGPathCreateMutable();
    CGPathMoveToPoint(bubblePath, NULL, _targetPoint.x+_sidePadding, _targetPoint.y);
    CGPathAddLineToPoint(bubblePath, NULL, _targetPoint.x+_sidePadding-_pointerSize, _targetPoint.y-_pointerSize);
    
    CGPathAddArcToPoint(bubblePath, NULL,
                        bubbleRect.origin.x, bubbleRect.origin.y+bubbleRect.size.height,
                        bubbleRect.origin.x, bubbleRect.origin.y+bubbleRect.size.height-_cornerRadius,
                        _cornerRadius);
    CGPathAddArcToPoint(bubblePath, NULL,
                        bubbleRect.origin.x, bubbleRect.origin.y,
                        bubbleRect.origin.x+_cornerRadius, bubbleRect.origin.y,
                        _cornerRadius);
    CGPathAddArcToPoint(bubblePath, NULL,
                        bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y,
                        bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y+_cornerRadius,
                        _cornerRadius);
    CGPathAddArcToPoint(bubblePath, NULL,
                        bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y+bubbleRect.size.height,
                        bubbleRect.origin.x+bubbleRect.size.width-_cornerRadius, bubbleRect.origin.y+bubbleRect.size.height,
                        _cornerRadius);
    CGPathAddLineToPoint(bubblePath, NULL, _targetPoint.x+_sidePadding+_pointerSize, _targetPoint.y-_pointerSize);
    
    CGPathCloseSubpath(bubblePath);
    
    CGContextSaveGState(c);
    CGContextAddPath(c, bubblePath);
    CGContextClip(c);
}
@end
